package com.blensmile.activity;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.blensmile.App;
import com.blensmile.BaseActivity;
import com.blensmile.R;
import com.blensmile.adapter.ImageAdapter;
import com.blensmile.utils.ImageToast;
import com.blensmile.utils.SysUtils;

import java.util.ArrayList;
import java.util.List;

public class WeightTest extends BaseActivity implements View.OnClickListener{

    private List<String> list = new ArrayList<>();
    private TextView tvClickMe;
    private ImageAdapter adapter;
    private RecyclerView recyclerView;
    private EditText etEdit;
    private FrameLayout fmFrame;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_weight_test);
        recyclerView = (RecyclerView)findViewById(R.id.rv_recycler);
        adapter = new ImageAdapter(this,list);
        recyclerView.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false));
        recyclerView.setAdapter(adapter);
        tvClickMe = (TextView)findViewById(R.id.tv_click);
        tvClickMe.setOnClickListener(this);
        etEdit = (EditText)findViewById(R.id.et_edit);
        fmFrame = (FrameLayout)findViewById(R.id.fm_frame);
        fmFrame.setOnClickListener(this);

    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_click:
                list.add("hello");
                adapter.notifyDataSetChanged();
                break;
            case R.id.fm_frame:
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                if(imm.isActive() && !etEdit.hasFocus()){
                    etEdit.requestFocus();
                }else {
                    etEdit.clearFocus();
                }
                break;
        }
    }
}
